/**
 * 
 */
package com.archerdu.apply.dao.hibernate;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.archerdu.apply.dao.ArticleDAO;
import com.archerdu.apply.model.Article;
import com.archerdu.base.dao.HibernateBaseDao;
import com.archerdu.base.dao.IPage;

/**
 * @author archer
 * @version 1.0.0
 */
public class ArticleDAOImpl extends HibernateBaseDao<Article, String> implements ArticleDAO{

	private static final long serialVersionUID = -7581594053093787176L;

	@SuppressWarnings("unchecked")
	@Override
	public List<Article> getLatest(String cateId, Integer recommend,
			Integer count) {
		DetachedCriteria crit = getCriteria();
		if(recommend != null)
			crit.add(Restrictions.eq("recommend", recommend));
		crit.add(Restrictions.eq("cateId", cateId));
		crit.addOrder(Order.desc("recommend"));
		crit.addOrder(Order.desc("createtime"));
		return this.getHibernateTemplate().findByCriteria(crit, 0, count);

	}

	@Override
	public IPage<Article> pageSearch(Article entity, int pageNo,
			int pageSize) {
		DetachedCriteria criteria = getCriteria();
		criteria.add(Example.create(entity));
		criteria.addOrder(Order.desc("createtime"));
		return pageSearch(criteria, pageNo, pageSize);	
	}
	
}
